import * as types from './mutations_types'
import { getDictionariesAllListAPI } from '@/api/system/dict/data'

export default {
  GetEducationList({ commit, state }, params = { request: true }) { // 获取学历列表-请求数据：默认必须走接口请求
    const { educationList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(educationList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_EDUCATION_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: educationList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetBankList({ commit, state }, params = { request: true }) { // 获取地区列表-请求数据：默认必须走接口请求
    const { bankList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(bankList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_BANK_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: bankList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetPoliticalList({ commit, state }, params = { request: true }) { // 获取地区列表-请求数据：默认必须走接口请求
    const { politicalList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(politicalList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_POLITICAL_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: politicalList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetMarryList({ commit, state }, params = { request: true }) { // 获取婚姻列表-请求数据：默认必须走接口请求
    const { marryList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(marryList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_MARRY_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: marryList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetNationList({ commit, state }, params = { request: true }) { // 获取民族列表-请求数据：默认必须走接口请求
    const { nationList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(nationList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_NATION_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: nationList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetInvoiceCompanyList({ commit, state }, params = { request: true }) { // 获取开票公司列表-请求数据：默认必须走接口请求
    const { invoiceCompanyList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(invoiceCompanyList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_INVOICECOMPANY_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: invoiceCompanyList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetUniformList({ commit, state }, params = { request: true }) { // 获取工装列表-请求数据：默认必须走接口请求
    const { uniformList } = state
    const { request } = params
    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(uniformList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_UNIFORM_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: uniformList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetSocialSecurityAccuracyList({ commit, state }, params = { request: true }) { // 获取社保费用尾数处理列表-请求数据：默认必须走接口请求
    const { socialSecurityAccuracyList } = state
    const { request } = params

    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(socialSecurityAccuracyList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_SOCIAL_ACCURACY_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: socialSecurityAccuracyList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  GetEmployeePostLevelList({ commit, state }, params = { request: true }) { // 获取社保费用尾数处理列表-请求数据：默认必须走接口请求
    const { employeePostLevelList } = state
    const { request } = params

    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(employeePostLevelList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_EMP_POST_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: employeePostLevelList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  },
  getEmployeeCompanyList({ commit, state }, params = { request: true }) { //
    const { employeeCompanyList } = state
    const { request } = params

    return new Promise((resolve, reject) => {
      if (request || JSON.stringify(employeeCompanyList) === '[]') {
        getDictionariesAllListAPI({
          ...params
        }).then(response => {
          // let result = response.data
          const result = response
          // console.log(result)
          if (+result.code === 200) {
            commit(types.SET_EMP_COM_LIST, result.rows || [])
            resolve(result)
          } else {
            reject(new Error(result.msg || '获取列表失败！'))
          }
        }).catch(error => {
          reject(error.message || '获取列表失败！')
        })
      } else {
        resolve({
          data: employeeCompanyList,
          msg: '交易成功',
          code: 200
        })
      }
    })
  }
}
